package com.ch.ms;


import com.ch.ms.server.login.MapleLoginServer;
import com.weibo.api.motan.common.MotanConstants;
import com.weibo.api.motan.util.MotanSwitcherUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication(scanBasePackages = "com.ch")
@EntityScan(basePackages = "com.ch.ms.data.domain", basePackageClasses = Jsr310JpaConverters.class)
@EnableJpaAuditing
public class MapleLoginServerApplication implements CommandLineRunner {

    private final MapleLoginServer mapleLoginServer;

    @Autowired
    public MapleLoginServerApplication(MapleLoginServer mapleLoginServer) {
        this.mapleLoginServer = mapleLoginServer;
    }

    @Value("${chms.servers.login.host}")
    private String host;

    @Value("${chms.servers.login.port}")
    private int port;

    @Override
    public void run(String... args) throws Exception {
        mapleLoginServer.bind(host, port);
    }


    public static void main(String[] args) throws Exception {

        SpringApplication.run(MapleLoginServerApplication.class, args);

        //注册服务到zookeeper
        MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);
    }


}
